<%@ page language="java" contentType= "text/html" pageEncoding="UTF-8"%>
<%@include file="/include/common/griduihead1.jsp"%>
<%@include file="/include/common/griduihead2.jsp"%>
<%
	page1.getPageTitle().setTitle("实体栏位维护");
	Map saveOption = new LinkedHashMap();
	saveOption.put("儲存","sav1");
	saveOption.put("從數據庫中同步","{id:'sav2',value:'sav2',confirm:'true'}");
	saveOption.put("生成流程欄位","{id:'sav3',value:'sav3',confirm:'true'}");
	
	Map searchOption = new LinkedHashMap();
	searchOption.put("查詢源表","s1");
	searchOption.put("查詢目標表","s2");
	searchOption.put("查詢欄位名","s3");
	
	DecimalFormat df = new DecimalFormat("0.#");
%>
<jm:form>
	<jm:layout postion="north">
		<jm:toolbar saveDisabled="false" saveOption="<%=saveOption%>" copyConfirm="true" copyDisabled="false" searchOption="<%=searchOption%>" exportDisabled="true" printDisabled="true" deleteDisabled="false"/>
		<jm:pageTitle />
		<jm:sp id="sp1" data="<%=Utils.TAG_FORM%>" tabSize="1">
			<jm:tab colModel="300px;*">
				<jm:combobox name="ptablesn" required="true" trigger="all" width="200px" caption="源表名" dataSource="pan" sql="select sn,tablename+'||'+rem from pan..pan_table order by srt" />
				<jm:combobox name="dtablesn" config="acwidth:400" trigger="all" width="200px" caption="目標表名" dataSource="pan" sql="select sn,tablename+'||'+rem from pan..pan_table order by srt" />
				<jm:combobox name="rtablesn" config="acwidth:400" trigger="all" width="200px" caption="當前表名" enab="false" dataSource="pan" sql="select sn,tablename+'||'+rem from pan..pan_table order by srt" />
				<input name="fieldname" type="text" caption="欄位名" /> 
			</jm:tab>
		</jm:sp>
		<jm:error></jm:error>
	</jm:layout>

	<jm:layout postion="center">
		<jm:columnEditors>
			<jm:columnEditor id="e_name" type="text">
		        <input name="e_name" type="text"/>
		    </jm:columnEditor>
		    <jm:columnEditor id="e_caption" type="text">
		        <input name="e_caption" type="text"/>
		    </jm:columnEditor>
		     <jm:columnEditor id="e_rem" type="text">
		        <input name="e_rem" type="text"/>
		    </jm:columnEditor>
			 <jm:columnEditor id="e_type" type="combobox">
		       	<jm:combobox name="e_type" codeList="nvarchar(50);nvarchar(100);nvarchar(200);int;datetime" trigger="all"/>
		    </jm:columnEditor>
		     <jm:columnEditor id="e_defalvalue" type="text">
		        <input name="e_defalvalue" type="text"/>
		    </jm:columnEditor>
		    <jm:columnEditor id="e_srt" type="text">
		        <input name="e_srt" type="text"/>
		    </jm:columnEditor>
		</jm:columnEditors>
		<jm:table id="grid1" dataSet="<%=ret.getSerchResult()%>" toolbar="true" loopFisrt="true" addRowConfig="reset:grid_reset" jump="true">
		    <jm:thead>
		        <tr>
		        	<td width="30px">选</td>
					<td width="30px">序号</td>
		            <td config="cid:'name',editor:'text',editorid:'e_name',eedit:'name_eedit'" width="100px">栏位名</td>
		            <td config="cid:'caption',editor:'text',editorid:'e_caption'" width="100px">标题</td>
		            <td config="cid:'rem',editor:'text',editorid:'e_rem'" width="100px">備註</td>
		            <td config="cid:'type',editor:'combobox',editorid:'e_type'" width="100px">类型</td>
		            <td config="cid:'defalvalue',editor:'text',editorid:'e_defalvalue'" width="150px">默认值</td>
		            <td config="cid:'srt',editor:'text',editorid:'e_srt',width:100" width="50px">排序</td>
		            <td width="50px">表名</td>
		            <td width="*">表[中文名]</td>
		        </tr>
		    </jm:thead>
		    <jm:tbody>
		        <jm:tr>
		            <jm:td><input type="checkbox" name="key" value="<%=ret.grsv("sn")%>" /></jm:td>				
					<jm:td>
						<span id="rownumber"><%=ret.getTableRowIndex()+1%></span>
						<input type="hidden" name="sn" value="<%=ret.grsv("sn")%>" />
						<input type="hidden" name="tablesn" value="<%=ret.grsv("tablesn1")%>" />
						<input type="hidden" name="datasource" value="<%=ret.grsv("datasource")%>" />
						<input type="hidden" name="database" value="<%=ret.grsv("database")%>" />
						<input type="hidden" name="tablename" value="<%=ret.grsv("tablename")%>" />
					</jm:td>
		            <jm:td cid="name"></jm:td>
		            <jm:td cid="caption"></jm:td>
		             <jm:td cid="rem"></jm:td>
		            <jm:td cid="type"></jm:td>
		            <jm:td cid="defalvalue"></jm:td>
		            <jm:td cid="srt"><%=df.format(ret.grdv("srt",1))%></jm:td>
		            <jm:td cid="tablename"></jm:td>
		            <jm:td cid="tablecnname"></jm:td>
		        </jm:tr>
		    </jm:tbody>  
		</jm:table> 		
	</jm:layout>
	<jm:layout postion="south"/>
</jm:form>
<jm:script><script type="text/javascript" charset="UTF-8">
	function onsave(actionvalue,p){
		var records = $('table[id=grid1] tbody tr[dirty=true]').getRecords();
		$P.form.appendRecords(records);
		submitForm(p);
	}
	
	function oncopy(actionvalue,p){
		var records = $('table[id=grid1] tbody tr:has(input[name=key]:checked)').getRecords();
		$P.form.appendRecords(records);
		submitForm(p);
	}
	
	function grid_reset(tr){
		tr.find('input[name=key]').remove();
		tr.find('input[name=sn]').val('');
		tr.find('span[id=rownumber],td[cid]').html('&nbsp;').attr('value',"");
		tr.find('td[cid=srt]').html($('table[id=grid1] td[cid=srt]').length+1);
		tr.find('td').attr('rowindex',$('table[id=grid1] td[cid=srt]').length);
	}
	
	function paramsfun_database(p){
		p['datasource'] = p['parentvalue'];
	}
	
	function name_eedit(config){
		var p ={};
		p['action'] = "getCaption";
		p['name'] = config['value'];
		if($P.isne(p['name']))return true;
		if(config['value'] == config['oldvalue'])return true;
		
		
		var tr = $(this).parent();
		var doaction = function(jo){
		   	if(jo != undefined && jo.ret == 1){
				tr.find("td[cid=caption]").text($(jo.data).gv("caption"));
			}	
		};
		$P.ajax({data : p,succ :doaction,async:true});
		return true;
	}
</script></jm:script>
<%@include file="/include/common/griduiend.jsp"%>
